鍵盤出入
輸入函數cin:
:是串列輸入符號(stream input),它依序將串列資料移入指定變數中。
int length                           //宣告整數變數length
cin >> length                         //輸入資料存入length
多重輸入cin
int width,height;                 //宣告變數width與height
cin >> width >> height            //分別存入width與height
cin練習:
#include <iostream>
using namespace std;
 
int main(int argc, char** argv)
{
    char key;                               //char 宣告字元變數key 
	cout << "按任意鍵:";                    //輸出訊息字串 
	cin >> key;                             //取得鍵盤輸入 
	cout << "輸入按鍵是?:" << key << endl;	//顯示訊息和輸入字元 	  
	system("PAUSE");
	return 0;
}
輸出結果:
輸出格式化
使用定位('\t')字元對齊輸出資料,但輸出卻因輸出數直有效位數不同,而影響定位輸出,使輸出資料無法對齊。
定位輸出:
#include <iostream>
using namespace std;
 
int main(int argc, char** argv)
{
    int n11 = 15, n12 = 265262662, n13 = 88;
    int n21 = -215611, n22 = 5, n23 = 246;
    cout << n11 << '\t'
         << n12 << '\t'
         << n13 << endl;
    cout << n21 << '\t'
         << n22 << '\t'
         << n23 << endl;     
	system("PAUSE");
	return 0;
}
輸出結果: